import java.util.Arrays;
import java.util.PriorityQueue;

public class Main {
    public static void main(String[] args) {
        int[] nums={5,19,8,1};
        System.out.println(halveArray(nums));
    }

    /**
     * 将数组和减半的最少操作次数
     * @param nums
     * @return
     */
    public static int halveArray(int[] nums) {
        PriorityQueue<Double> heap=new PriorityQueue<>((a,b)->b.compareTo(a));//大根堆
        double sum=0;
        for(int x:nums){
            sum+=x;
            heap.offer((double)x);
        }
        sum/=2.0;
        int count=0;
        while(sum>0){
            double num=heap.poll()/2;
            sum-=num;
            heap.offer(num);
            count++;
        }
        return count;
    }

    /**
     * 最大数
     * @param nums
     * @return
     */
    public static String largestNumber(int[] nums) {
        int n=nums.length;
        String[] strs=new String[n];
        for(int i=0;i<n;i++){
            strs[i]=""+nums[i];
        }
        Arrays.sort(strs,(a,b)->{
            return (b+a).compareTo(a+b);
        });
        StringBuffer ret=new StringBuffer();
        for(String s:strs){
            ret.append(s);
        }
        if(ret.charAt(0)=='0'){
            return "0";
        }
        return ret.toString();
    }
}